package com.sikao.app.ui;

import android.content.Intent;
import android.os.Bundle;
import android.text.Editable;
import android.text.TextUtils;
import android.text.TextWatcher;
import android.view.Gravity;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.Switch;
import android.widget.TextView;
import android.widget.Toast;

import com.cnzhizi.multilist.bean.FilterEntity;
import com.cnzhizi.wheelpop.model.OneModel;
import com.cnzhizi.wheelpop.model.ThreeModel;
import com.cnzhizi.wheelpop.model.TwoModel;
import com.cnzhizi.wheelpop.ui.SkmDatePickerPopup;
import com.cnzhizi.wheelpop.ui.SkmModiPopup;
import com.sikao.app.R;
import com.sikao.app.bean.AddGoodsParamBean;
import com.sikao.app.bean.AddGoodsStepOneBean;
import com.sikao.app.bean.AddGoodsStepOneSubmitBean;
import com.sikao.app.bean.AreaBean;
import com.sikao.app.bean.AreaSubmitBean;
import com.sikao.app.bean.CalculateCreditBean;
import com.sikao.app.bean.CalculateCreditSubmitBean;
import com.sikao.app.bean.CalculateMarginBean;
import com.sikao.app.bean.CalculateMarginSubmitBean;
import com.sikao.app.bean.GetInfoByNamePhoneBean;
import com.sikao.app.bean.GetInfoByNamePhoneSubmitBean;
import com.sikao.app.bean.GoodsCategoryBeanTest;
import com.sikao.app.bean.GoodsCategorySubmitBean;
import com.sikao.app.bean.OwnGoodsDetailBean;
import com.sikao.app.bean.OwnGoodsDetailSubmitBean;
import com.sikao.app.dao.AddGoodsParamModel;
import com.sikao.app.dao.AddGoodsStepOneModel;
import com.sikao.app.dao.AreaBeanModel;
import com.sikao.app.dao.CalculateCreditModel;
import com.sikao.app.dao.CalculateMarginModel;
import com.sikao.app.dao.GetInfoByNamePhoneModel;
import com.sikao.app.dao.GoodsCategoryModelTest;
import com.sikao.app.dao.OwnGoodsDetailModel;
import com.sikao.app.net.OnNetBackListener;
import com.sikao.app.ui.base.BaseActivity;
import com.sikao.app.utils.ConstantClass;
import com.sikao.app.utils.JSONUtil;
import com.sikao.app.utils.TimeUtil;
import com.sikao.app.utils.Utils;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.List;
import java.util.Timer;
import java.util.TimerTask;

/**
 * 卖家中心发布商品模块
 */
public class ReleaseGoodsActivity extends BaseActivity implements View.OnClickListener {

	public static final int STEP_PRICE_REQUEST_CODE = 10001;//添加阶梯价格请求的code
	public static final int STEP_PRICE_RESULT_CODE = 100010;//添加阶梯价格正常返回的code
	public static final int PAY_REQUEST_CODE = 10002;//保证金付款请求的code
	public static final int PAY_RESULT_CODE = 100020;//保证金付款正常返回的code
	public static final int STORE_PIC_REQUEST_CODE = 10003;//添加仓单图片请求的code
	public static final int STORE_PIC_RESULT_CODE = 100030;//添加仓单正常返回的code

	public static final int STEP_TWO_REQUEST_CODE = 10004;//添加添加附加信息 第二步请求的code
	public static final int STEP_TWO_RESULT_CODE = 100040;//添加添加附加信息 第二步正常返回的code


	private TextView titleTv;
	private TextView title_right_tv;
	private ImageView backIv;
	private Button bt_check_user;


	//商品分类
	private String classifyId;
	//货品名称
	private String goodsTitle;
	//产品品牌
	private String goodsProductCode = "";
	//单位
	private String goodsUnit;
	//数量
	private String goodsNumber;
	//发布类型
	private String goodsPushTypeId;
	//商城单价
	private String goodsPrice;
	//是否拆分出售
	private int goodsIssplit = 1;
	//最小供应量
	private int goodsLeastNumber = 0;
	//最小供应量单位
	// private String goodsLeastNumberUnit;
	//阶梯价格的id集合
	private String stepPrice;
	//起拍价 (总价)
	private String goodsTotalPrice;
	//最低加价幅度
	private double goodsLeastAdd;
	//一口价stepPrice
	private double goodsFixedPrice;
	//

	//支付方式
	private int goodsPaytype;
	//分期比例
	private double scaleOne;
	private double scaleTwo;
	private double scaleThree;
	//挂单方式
	private int goodsPublishTypeId;

	//定向用户
	private String goodsToUser;
	//交割地
	private String deliveryArea;
	private String province;
	private String city;
	private String county;
	//交割方式
	private String goodsDeliveryType;
	//开始日期
	private String startTime;
	//结束日期
	private String endTime;
	//备注
	private String remark;
	//是否启用阶梯价格
	private boolean isUseStepPrice = false;
	//是否启用仓单图片
	private boolean isUsestorePic = false;

	private  String storePic="";

	private RelativeLayout rlReleaseGoodsClassify;
	private TextView tvReleaseGoodsClassify;
	private EditText etReleaseGoodsTitle;
	private EditText etReleaseGoodsProductCode;
	private RelativeLayout rlReleaseGoodsPushType;
	private TextView tvReleaseGoodsPushType;
	private TextView tvReleaseGoodsUnit;
	private EditText etReleaseGoodsNumber;
	private LinearLayout llReleaseGoodsForMall;
	private EditText etReleaseGoodsPrice;
	private RelativeLayout rlReleaseGoodsIssplit;
	private TextView tvReleaseGoodsIssplit;
	private TextView tvReleaseGoodsLeastNumberUnit;
	private LinearLayout rlReleaseGoodsLeastNumber;
	private EditText etReleaseGoodsLeastNumber;
	private RelativeLayout rlReleaseGoodsStepPrice;
	private TextView tvReleaseGoodsStepPrice;
	private LinearLayout llReleaseGoodsForAuction;
	private EditText etReleaseGoodsTotalPrice;
	private EditText etReleaseGoodsBuyMargin;
	private EditText etReleaseGoodsLeastAdd;
	private EditText etReleaseGoodsFixedPrice;
	private RelativeLayout rlReleaseGoodsPaytype;
	private TextView tvReleasePaytype;
	private LinearLayout llReleaseGoodsPaytypeForInstallment;
	private EditText etScaleOne;
	private EditText etScaleTwo;
	private EditText etScaleThree;
	private RelativeLayout rlReleaseGoodsPublishType;
	private TextView tvReleaseGoodsPublishType;
	private RelativeLayout rlReleaseGoodsStorePic;
	private TextView tvReleaseGoodsStorePic;
	private RelativeLayout rlReleaseGoodsSellMargin;
	private TextView tvCash;
	private TextView tvMargin;
	private RelativeLayout rlReleaseGoodsSellCredit;
	private TextView tvOwncredit;
	private TextView tvCredit;
	private LinearLayout rlReleaseGoodsToUser;
	private EditText etReleaseGoodsToUser;
	private RelativeLayout rlReleaseGoodsDeliveryArea;
	private TextView tvReleaseGoodsDeliveryArea;
	private RelativeLayout rlReleaseGoodsDeliveryType;
	private TextView tvReleaseGoodsDeliveryType;
	private RelativeLayout rlReleaseGoodsStartTime;
	private TextView tvReleaseGoodsStartTime;
	private RelativeLayout rlReleaseGoodsEndTime;
	private TextView tvReleaseGoodsEndTime;
	private EditText etReleaseGoodsRemark;
	private int releaseGoodsState = 1;
	private int goodsId = 0;

	private String goodsStatus = "";
	private String catId = "";
	private String objectId = "";

	//参数
	private AddGoodsParamBean addGoodsParamBean;
	//添加商品第一步提交的信息
	private AddGoodsStepOneSubmitBean addGoodsStepOneSubmitBean = new AddGoodsStepOneSubmitBean();
	//获取的商品详情
	private OwnGoodsDetailBean ownGoodsDetailBean;

	private String payPassword="";
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		setContentView(R.layout.activity_release_goods);
		super.onCreate(savedInstanceState);
	}

	@Override
	protected void initData() {
		/*
						（1）、初次进入 1
                        （2）、第二步返回状态 2
                        （3）、查询重新编辑状态3
                      (4)(商品的状态goodsStatus)status:0.1不可编辑; status:-1.2可编辑 ;这是发布商品那边的

                      修改2017.01.04 审核状态为2 是不可编辑的

                        releaseGoodsState  1，2，3

                        releaseGoodsState状态为3的时候需要goodsId goodsStatus参数
						 */
		Intent intent = getIntent();
		releaseGoodsState = intent.getIntExtra("releaseGoodsState", 1);
		Utils.showLog("=======发布商品第一步 releaseGoodsState：" + releaseGoodsState);
		if (releaseGoodsState == 3) {
			goodsId = intent.getIntExtra("goodsId", 0);
			goodsStatus = intent.getStringExtra("goodsStatus");
		}
	}

	@Override
	protected void initView() {
		titleTv = (TextView) findViewById(R.id.title_middle_tv);
		title_right_tv = (TextView) findViewById(R.id.title_right_tv);
		backIv = (ImageView) findViewById(R.id.title_left_img);
		rlReleaseGoodsClassify = (RelativeLayout) findViewById(R.id.rl_release_goods_classify);
		tvReleaseGoodsClassify = (TextView) findViewById(R.id.tv_release_goods_classify);
		etReleaseGoodsTitle = (EditText) findViewById(R.id.et_release_goods_title);
		etReleaseGoodsProductCode = (EditText) findViewById(R.id.et_release_goods_product_code);
		rlReleaseGoodsPushType = (RelativeLayout) findViewById(R.id.rl_release_goods_push_type);
		tvReleaseGoodsPushType = (TextView) findViewById(R.id.tv_release_goods_push_type);
		tvReleaseGoodsUnit = (TextView) findViewById(R.id.tv_release_goods_unit);
		etReleaseGoodsNumber = (EditText) findViewById(R.id.et_release_goods_number);
		llReleaseGoodsForMall = (LinearLayout) findViewById(R.id.ll_release_goods_for_mall);
		etReleaseGoodsPrice = (EditText) findViewById(R.id.et_release_goods_price);
		rlReleaseGoodsIssplit = (RelativeLayout) findViewById(R.id.rl_release_goods_issplit);
		tvReleaseGoodsIssplit = (TextView) findViewById(R.id.tv_release_goods_issplit);
		tvReleaseGoodsLeastNumberUnit = (TextView) findViewById(R.id.tv_release_goods_least_number_unit);
		rlReleaseGoodsLeastNumber = (LinearLayout) findViewById(R.id.rl_release_goods_least_number);
		etReleaseGoodsLeastNumber = (EditText) findViewById(R.id.et_release_goods_least_number);
		rlReleaseGoodsStepPrice = (RelativeLayout) findViewById(R.id.rl_release_goods_step_price);
		tvReleaseGoodsStepPrice = (TextView) findViewById(R.id.tv_release_goods_step_price);
		llReleaseGoodsForAuction = (LinearLayout) findViewById(R.id.ll_release_goods_for_auction);
		etReleaseGoodsTotalPrice = (EditText) findViewById(R.id.et_release_goods_total_price);
		etReleaseGoodsBuyMargin = (EditText) findViewById(R.id.et_release_goods_buy_margin);
		etReleaseGoodsLeastAdd = (EditText) findViewById(R.id.et_release_goods_least_add);
		etReleaseGoodsFixedPrice = (EditText) findViewById(R.id.et_release_goods_fixed_price);
		rlReleaseGoodsPaytype = (RelativeLayout) findViewById(R.id.rl_release_goods_paytype);
		tvReleasePaytype = (TextView) findViewById(R.id.tv_release_paytype);
		llReleaseGoodsPaytypeForInstallment = (LinearLayout) findViewById(R.id.ll_release_goods_paytype_for_installment);
		etScaleOne = (EditText) findViewById(R.id.et_scale_one);
		etScaleTwo = (EditText) findViewById(R.id.et_scale_two);
		etScaleThree = (EditText) findViewById(R.id.et_scale_three);
		rlReleaseGoodsPublishType = (RelativeLayout) findViewById(R.id.rl_release_goods_publish_type);
		tvReleaseGoodsPublishType = (TextView) findViewById(R.id.tv_release_goods_publish_type);
		rlReleaseGoodsStorePic = (RelativeLayout) findViewById(R.id.rl_release_goods_store_pic);
		tvReleaseGoodsStorePic = (TextView) findViewById(R.id.tv_release_goods_store_pic);
		rlReleaseGoodsSellMargin = (RelativeLayout) findViewById(R.id.rl_release_goods_sell_margin);
		tvCash = (TextView) findViewById(R.id.tv_cash);
		tvMargin = (TextView) findViewById(R.id.tv_margin);
		rlReleaseGoodsSellCredit = (RelativeLayout) findViewById(R.id.rl_release_goods_sell_credit);
		tvOwncredit = (TextView) findViewById(R.id.tv_owncredit);
		tvCredit = (TextView) findViewById(R.id.tv_credit);
		rlReleaseGoodsToUser = (LinearLayout) findViewById(R.id.rl_release_goods_to_user);
		etReleaseGoodsToUser = (EditText) findViewById(R.id.et_release_goods_to_user);
		rlReleaseGoodsDeliveryArea = (RelativeLayout) findViewById(R.id.rl_release_goods_delivery_area);
		tvReleaseGoodsDeliveryArea = (TextView) findViewById(R.id.tv_release_goods_delivery_area);
		rlReleaseGoodsDeliveryType = (RelativeLayout) findViewById(R.id.rl_release_goods_delivery_type);
		tvReleaseGoodsDeliveryType = (TextView) findViewById(R.id.tv_release_goods_delivery_type);
		rlReleaseGoodsStartTime = (RelativeLayout) findViewById(R.id.rl_release_goods_start_time);
		tvReleaseGoodsStartTime = (TextView) findViewById(R.id.tv_release_goods_start_time);
		rlReleaseGoodsEndTime = (RelativeLayout) findViewById(R.id.rl_release_goods_end_time);
		tvReleaseGoodsEndTime = (TextView) findViewById(R.id.tv_release_goods_end_time);
		etReleaseGoodsRemark = (EditText) findViewById(R.id.et_release_goods_remark);
		bt_check_user = (Button) findViewById(R.id.bt_check_user);
	}

	@Override
	protected void initListener() {

		backIv.setOnClickListener(this);
		title_right_tv.setOnClickListener(this);//下一步
		//阶梯价格
		rlReleaseGoodsStepPrice.setOnClickListener(this);
		//仓单挂单
		rlReleaseGoodsStorePic.setOnClickListener(this);
		if (releaseGoodsState == 1) {
			//分类
			rlReleaseGoodsClassify.setOnClickListener(this);

			//发布类型
			rlReleaseGoodsPushType.setOnClickListener(this);
			//是否拆分
			rlReleaseGoodsIssplit.setOnClickListener(this);
			//支付方式
			rlReleaseGoodsPaytype.setOnClickListener(this);
			//挂单方式
			rlReleaseGoodsPublishType.setOnClickListener(this);
			//交割方式
			rlReleaseGoodsDeliveryType.setOnClickListener(this);
			//所在地
			rlReleaseGoodsDeliveryArea.setOnClickListener(this);
			//开始时间
			rlReleaseGoodsStartTime.setOnClickListener(this);
			//结束时间
			rlReleaseGoodsEndTime.setOnClickListener(this);

			bt_check_user.setOnClickListener(this);


			etReleaseGoodsNumber.addTextChangedListener(new TextWatcher() {
				@Override
				public void beforeTextChanged(CharSequence s, int start, int count, int after) {

				}

				@Override
				public void onTextChanged(CharSequence s, int start, int before, int count) {

				}

				@Override
				public void afterTextChanged(Editable s) {

					calculateMarginAndCredit();

				}
			});
			etReleaseGoodsPrice.addTextChangedListener(new TextWatcher() {
				@Override
				public void beforeTextChanged(CharSequence s, int start, int count, int after) {

				}

				@Override
				public void onTextChanged(CharSequence s, int start, int before, int count) {

				}

				@Override
				public void afterTextChanged(Editable s) {

					calculateMarginAndCredit();
				}
			});
			etReleaseGoodsTotalPrice.addTextChangedListener(new TextWatcher() {
				@Override
				public void beforeTextChanged(CharSequence s, int start, int count, int after) {

				}

				@Override
				public void onTextChanged(CharSequence s, int start, int before, int count) {

				}

				@Override
				public void afterTextChanged(Editable s) {

					calculateMarginAndCredit();

				}
			});

		} else {

			//分类
			rlReleaseGoodsClassify.setEnabled(false);

			//发布类型
			rlReleaseGoodsPushType.setEnabled(false);
			//是否拆分
			rlReleaseGoodsIssplit.setEnabled(false);
			//支付方式
			rlReleaseGoodsPaytype.setEnabled(false);
			//挂单方式
			rlReleaseGoodsPublishType.setEnabled(false);
			//交割方式
			rlReleaseGoodsDeliveryType.setEnabled(false);
			//所在地
			rlReleaseGoodsDeliveryArea.setEnabled(false);
			//开始时间
			rlReleaseGoodsStartTime.setEnabled(false);
			//结束时间
			rlReleaseGoodsEndTime.setEnabled(false);
			bt_check_user.setEnabled(false);

			etReleaseGoodsBuyMargin.setEnabled(false);
			etReleaseGoodsFixedPrice.setEnabled(false);
			etReleaseGoodsLeastAdd.setEnabled(false);
			etReleaseGoodsLeastNumber.setEnabled(false);
			etReleaseGoodsNumber.setEnabled(false);
			etReleaseGoodsPrice.setEnabled(false);
			etReleaseGoodsProductCode.setEnabled(false);
			etReleaseGoodsRemark.setEnabled(false);
			etReleaseGoodsTitle.setEnabled(false);
			etReleaseGoodsTotalPrice.setEnabled(false);
			etReleaseGoodsToUser.setEnabled(false);
			etScaleOne.setEnabled(false);
			etScaleTwo.setEnabled(false);
			etScaleThree.setEnabled(false);

		}
	}

	@Override
	protected void init() {
		titleTv.setText("发布商品");
		backIv.setVisibility(View.VISIBLE);
		title_right_tv.setVisibility(View.VISIBLE);
		title_right_tv.setText("下一步");
		//加载页面的时候 从后台获取参数  判断releaseGoodsState  的值
		if (releaseGoodsState == 1) {//发布商品进入的
			new AddGoodsParamModel(this, new OnNetBackListener<AddGoodsParamBean>() {
				@Override
				public void netBack(AddGoodsParamBean data) {
					if (data == null) {
						Toast.makeText(ReleaseGoodsActivity.this, data.getMsg(), Toast.LENGTH_SHORT).show();
					} else {
						if (data.getStatus() == 1) {
							addGoodsParamBean = data;
							initViewData();
						} else {
							Toast.makeText(ReleaseGoodsActivity.this, data.getMsg(), Toast.LENGTH_SHORT).show();
						}
					}
				}
			}).request("{}", true);
		} else if (releaseGoodsState == 2) {//返回进入的

		} else if (releaseGoodsState == 3) {//点击详情进入的
			OwnGoodsDetailSubmitBean ownGoodsDetailSubmitBean = new OwnGoodsDetailSubmitBean();
			ownGoodsDetailSubmitBean.setGoodsId(goodsId + "");
			new OwnGoodsDetailModel(this, new OnNetBackListener<OwnGoodsDetailBean>() {
				@Override
				public void netBack(OwnGoodsDetailBean data) {
					if (data == null) {
						Toast.makeText(ReleaseGoodsActivity.this, data.getMsg(), Toast.LENGTH_SHORT).show();
					} else {
						if (data.getStatus() == 1) {
							ownGoodsDetailBean = data;
							initViewDataForDetail();
						} else {
							Toast.makeText(ReleaseGoodsActivity.this, data.getMsg(), Toast.LENGTH_SHORT).show();
						}
					}
				}
			}).request(JSONUtil.toJSON(ownGoodsDetailSubmitBean), true);

		}
	}


	/**
	 * 将参数项 作为初始值 放到页面上
	 */

	/**
	 * 发布类型
	 * id : 0
	 * value : 商城
	 */

	private List<AddGoodsParamBean.ResBean.AddToBean> addToList;
	/**
	 * id : 0
	 * value : 否
	 */

	private List<AddGoodsParamBean.ResBean.IsPortedBean> isPortedList;
	/**
	 * id : 1
	 * value : 全款
	 */

	private List<AddGoodsParamBean.ResBean.PayTypeBean> payTypeList;
	/**
	 * id : 1
	 * value : 仓单挂单
	 */

	private List<AddGoodsParamBean.ResBean.PublishTypeBean> publishTypeList;
	/**
	 * id : 1
	 * value : 买家自提
	 */

	private List<AddGoodsParamBean.ResBean.DeliveryTypeBean> deliveryTypeList;

	/**
	 * id : 0
	 * value : 余额
	 */


	private void initViewData() {
		addToList = addGoodsParamBean.getRes().getAddTo();
		isPortedList = addGoodsParamBean.getRes().getIsPorted();
		payTypeList = addGoodsParamBean.getRes().getPayType();
		publishTypeList = addGoodsParamBean.getRes().getPublishType();
		deliveryTypeList = addGoodsParamBean.getRes().getDeliveryType();


		//发布类型默认值
		tvReleaseGoodsPushType.setText(addToList.get(0).getValue());
		switch (addToList.get(0).getId()) {
			case 0://商城
				llReleaseGoodsForMall.setVisibility(View.VISIBLE);
				llReleaseGoodsForAuction.setVisibility(View.GONE);
				rlReleaseGoodsToUser.setVisibility(View.GONE);
				rlReleaseGoodsIssplit.setVisibility(View.VISIBLE);//显示是否拆分出售
				rlReleaseGoodsStepPrice.setVisibility(View.VISIBLE);//显示阶梯价格
				rlReleaseGoodsLeastNumber.setVisibility(View.VISIBLE);//显示最小订货量
				if (isUseStepPrice) {//是否使用阶梯价格
					tvReleaseGoodsStepPrice.setText("启用");
				} else {
					tvReleaseGoodsStepPrice.setText("未启用");
				}
				break;
			case 1://拍卖
				llReleaseGoodsForMall.setVisibility(View.GONE);
				llReleaseGoodsForAuction.setVisibility(View.VISIBLE);
				rlReleaseGoodsToUser.setVisibility(View.GONE);
				//不可拆分出售
				addGoodsStepOneSubmitBean.setIsPorted("0");

				break;
			case 2://定向单
				llReleaseGoodsForMall.setVisibility(View.VISIBLE);
				llReleaseGoodsForAuction.setVisibility(View.GONE);
				rlReleaseGoodsToUser.setVisibility(View.VISIBLE);
				//不可拆分出售
				addGoodsStepOneSubmitBean.setIsPorted("0");
				rlReleaseGoodsIssplit.setVisibility(View.GONE);//隐藏是否拆分出售
				rlReleaseGoodsStepPrice.setVisibility(View.GONE);//不可拆分就隐藏阶梯价格
				rlReleaseGoodsLeastNumber.setVisibility(View.GONE);//隐藏最小订货量
				break;
		}
		//保存发布类型的值
		addGoodsStepOneSubmitBean.setAddTo(addToList.get(0).getId() + "");
		addTo = Integer.parseInt(addGoodsStepOneSubmitBean.getAddTo());

		//是否拆分出售默认值
		tvReleaseGoodsIssplit.setText(isPortedList.get(0).getValue());
		if (isPortedList.get(0).getId() == 0) {//不可拆分
			rlReleaseGoodsLeastNumber.setVisibility(View.GONE);
			rlReleaseGoodsStepPrice.setVisibility(View.GONE);//不可拆分就隐藏阶梯价格
			etReleaseGoodsLeastNumber.setText("");
			isUseStepPrice = false;
			stepPrice = "";
			addGoodsStepOneSubmitBean.setStepPrice(stepPrice);
		} else {
			rlReleaseGoodsLeastNumber.setVisibility(View.VISIBLE);
			rlReleaseGoodsStepPrice.setVisibility(View.VISIBLE);//可拆分就显示阶梯价格
		}
		addGoodsStepOneSubmitBean.setIsPorted(isPortedList.get(0).getId() + "");
		//支付方式默认值
		tvReleasePaytype.setText(payTypeList.get(0).getValue());
		switch (payTypeList.get(0).getId()) {
			case 1://全款
				//隐藏分期ui
				llReleaseGoodsPaytypeForInstallment.setVisibility(View.GONE);
				//设置分期的textview的值
				etScaleOne.setText("100");
				etScaleTwo.setText("0");
				etScaleThree.setText("0");
				break;
			case 2://分期
				//显示分期ui
				llReleaseGoodsPaytypeForInstallment.setVisibility(View.VISIBLE);
				//设置分期的textview的值
				etScaleOne.setText("0");
				etScaleTwo.setText("0");
				etScaleThree.setText("0");
				break;
			case 3://货到付款
				//隐藏分期ui
				llReleaseGoodsPaytypeForInstallment.setVisibility(View.GONE);
				//设置分期的textview的值
				etScaleOne.setText("0");
				etScaleTwo.setText("0");
				etScaleThree.setText("100");
				break;
		}

		addGoodsStepOneSubmitBean.setPayType(payTypeList.get(0).getId() + "");
		//挂单方式默认值
		tvReleaseGoodsPublishType.setText(publishTypeList.get(0).getValue());
		switch (publishTypeList.get(0).getId()) {
			case 1://1仓单挂单
				rlReleaseGoodsStorePic.setVisibility(View.VISIBLE);
				rlReleaseGoodsSellMargin.setVisibility(View.GONE);
				rlReleaseGoodsSellCredit.setVisibility(View.GONE);
				if (isUsestorePic) {
					tvReleaseGoodsStorePic.setText("已添加");
				} else {
					tvReleaseGoodsStorePic.setText("未添加");
				}

				break;
			case 2://2保证金挂单
				rlReleaseGoodsStorePic.setVisibility(View.GONE);
				rlReleaseGoodsSellMargin.setVisibility(View.VISIBLE);
				rlReleaseGoodsSellCredit.setVisibility(View.GONE);
				//计算保证金
				//calculateMargin();

				break;
			case 3://3信誉挂单
				rlReleaseGoodsStorePic.setVisibility(View.GONE);
				rlReleaseGoodsSellMargin.setVisibility(View.GONE);
				rlReleaseGoodsSellCredit.setVisibility(View.VISIBLE);
				//计算信誉值
				//calculateCredit();
				break;
		}

		addGoodsStepOneSubmitBean.setPublishType(publishTypeList.get(0).getId() + "");
		//交割方式默认值
		tvReleaseGoodsDeliveryType.setText(deliveryTypeList.get(0).getValue());
		addGoodsStepOneSubmitBean.setDeliveryType(deliveryTypeList.get(0).getId() + "");

		//初始化滚轮的值
  /*        oneModelListForGoodsPushType //发布类型滚轮一级
		  oneModelListForGoodsIssplit  //是否拆分滚轮一级
       oneModelListForGoodsPaytype  //支付方式滚轮一级
         oneModelListForGoodsPublishType //挂单方式滚轮一级
         oneModelListForGoodsDeliveryType//交割方式滚轮一级*/

		for (int i = 0; i < addToList.size(); i++) {
			OneModel oneModel = new OneModel();
			oneModel.setId(addToList.get(i).getId() + "");
			oneModel.setName(addToList.get(i).getValue());
			oneModelListForGoodsPushType.add(oneModel);
		}
		for (int i = 0; i < isPortedList.size(); i++) {
			OneModel oneModel = new OneModel();
			oneModel.setId(isPortedList.get(i).getId() + "");
			oneModel.setName(isPortedList.get(i).getValue());
			oneModelListForGoodsIssplit.add(oneModel);
		}
		for (int i = 0; i < payTypeList.size(); i++) {
			OneModel oneModel = new OneModel();
			oneModel.setId(payTypeList.get(i).getId() + "");
			oneModel.setName(payTypeList.get(i).getValue());
			oneModelListForGoodsPaytype.add(oneModel);
		}
		for (int i = 0; i < publishTypeList.size(); i++) {
			OneModel oneModel = new OneModel();
			oneModel.setId(publishTypeList.get(i).getId() + "");
			oneModel.setName(publishTypeList.get(i).getValue());
			oneModelListForGoodsPublishType.add(oneModel);
		}
		for (int i = 0; i < deliveryTypeList.size(); i++) {
			OneModel oneModel = new OneModel();
			oneModel.setId(deliveryTypeList.get(i).getId() + "");
			oneModel.setName(deliveryTypeList.get(i).getValue());
			oneModelListForGoodsDeliveryType.add(oneModel);
		}
	}

	/**
	 * 从商品详情进入的 给界面赋值
	 */
	private void initViewDataForDetail() {
		//商品状态
		goodsStatus=ownGoodsDetailBean.getRes().getStatus();
		//商品分类id
		catId = ownGoodsDetailBean.getRes().getCat_id();
		//商品id
		objectId = ownGoodsDetailBean.getRes().getId();

		tvReleaseGoodsClassify.setText(ownGoodsDetailBean.getRes().getCat_name());
		etReleaseGoodsTitle.setText(ownGoodsDetailBean.getRes().getTitle());
		etReleaseGoodsProductCode.setText(ownGoodsDetailBean.getRes().getProduct_code());
		etReleaseGoodsNumber.setText(ownGoodsDetailBean.getRes().getNumber());
		tvReleaseGoodsUnit.setText("(" + ownGoodsDetailBean.getRes().getUnit() + ")：");
		tvReleaseGoodsLeastNumberUnit.setText("(" + ownGoodsDetailBean.getRes().getUnit() + ")：");
		goodsUnit = ownGoodsDetailBean.getRes().getUnit();
		//发布类型
		tvReleaseGoodsPushType.setText(ownGoodsDetailBean.getRes().getAdd_to_str());

		//判断是否使用了阶梯价格
		List<OwnGoodsDetailBean.ResBean.StepPriceBean> stepPriceList = ownGoodsDetailBean.getRes().getStep_price();
		isUseStepPrice = stepPriceList.size() > 0;

		//发布类型展示规则
		addTo = Integer.parseInt(ownGoodsDetailBean.getRes().getAdd_to());

		switch (addTo) {
			case 0://商城
				llReleaseGoodsForMall.setVisibility(View.VISIBLE);
				llReleaseGoodsForAuction.setVisibility(View.GONE);
				rlReleaseGoodsToUser.setVisibility(View.GONE);
				rlReleaseGoodsIssplit.setVisibility(View.VISIBLE);//显示是否拆分出售
				rlReleaseGoodsStepPrice.setVisibility(View.VISIBLE);//显示阶梯价格
				rlReleaseGoodsLeastNumber.setVisibility(View.VISIBLE);//显示最小订货量
				if (isUseStepPrice) {//是否使用阶梯价格
					tvReleaseGoodsStepPrice.setText("启用");
				} else {
					tvReleaseGoodsStepPrice.setText("未启用");
				}

				etReleaseGoodsPrice.setText(ownGoodsDetailBean.getRes().getPrice());
				break;
			case 1://拍卖
				llReleaseGoodsForMall.setVisibility(View.GONE);
				llReleaseGoodsForAuction.setVisibility(View.VISIBLE);
				rlReleaseGoodsToUser.setVisibility(View.GONE);
				//不可拆分出售
				//addGoodsStepOneSubmitBean.setIsPorted("0");
				etReleaseGoodsTotalPrice.setText(ownGoodsDetailBean.getRes().getTotal_price());
				etReleaseGoodsBuyMargin.setText(ownGoodsDetailBean.getRes().getBuy_margin());
				etReleaseGoodsLeastAdd.setText(ownGoodsDetailBean.getRes().getLeast_add());
				etReleaseGoodsFixedPrice.setText(ownGoodsDetailBean.getRes().getFixed_price());

				break;
			case 2://定向单
				llReleaseGoodsForMall.setVisibility(View.VISIBLE);
				llReleaseGoodsForAuction.setVisibility(View.GONE);
				rlReleaseGoodsToUser.setVisibility(View.VISIBLE);
				//不可拆分出售
				// addGoodsStepOneSubmitBean.setIsPorted("0");
				rlReleaseGoodsIssplit.setVisibility(View.GONE);//隐藏是否拆分出售
				rlReleaseGoodsStepPrice.setVisibility(View.GONE);//不可拆分就隐藏阶梯价格
				rlReleaseGoodsLeastNumber.setVisibility(View.GONE);//隐藏最小订货量

				etReleaseGoodsPrice.setText(ownGoodsDetailBean.getRes().getPrice());
				etReleaseGoodsToUser.setText(ownGoodsDetailBean.getRes().getTo_user_phone()+"");
				break;
		}


		//是否拆分出售
		Utils.showLog("======ownGoodsDetailBean.getRes().getIs_ported():" + ownGoodsDetailBean.getRes().getIs_ported());
		goodsIssplit = Integer.parseInt(ownGoodsDetailBean.getRes().getIs_ported());//是否可拆分 0不可 1可拆分

		tvReleaseGoodsIssplit.setText(ownGoodsDetailBean.getRes().getIs_ported_str());


		if (goodsIssplit == 0) {//不可拆分
			rlReleaseGoodsLeastNumber.setVisibility(View.GONE);
			rlReleaseGoodsStepPrice.setVisibility(View.GONE);//不可拆分就隐藏阶梯价格

		} else {
			rlReleaseGoodsLeastNumber.setVisibility(View.VISIBLE);
			rlReleaseGoodsStepPrice.setVisibility(View.VISIBLE);//可拆分就显示阶梯价格
			etReleaseGoodsLeastNumber.setText(ownGoodsDetailBean.getRes().getLeast_number());
		}
		//支付方式
		tvReleasePaytype.setText(ownGoodsDetailBean.getRes().getPay_type_str());
		String[] payScaleData = ownGoodsDetailBean.getRes().getPay_scale().split(",");

		int payTypeId = Integer.parseInt(ownGoodsDetailBean.getRes().getPay_type());

		switch (payTypeId) {
			case 1://全款
				//隐藏分期ui
				llReleaseGoodsPaytypeForInstallment.setVisibility(View.GONE);
				//设置分期的textview的值
				etScaleOne.setText(payScaleData[0]);
				etScaleTwo.setText(payScaleData[1]);
				etScaleThree.setText(payScaleData[2]);
				break;
			case 2://分期
				//显示分期ui
				llReleaseGoodsPaytypeForInstallment.setVisibility(View.VISIBLE);
				//设置分期的textview的值
				etScaleOne.setText(payScaleData[0]);
				etScaleTwo.setText(payScaleData[1]);
				etScaleThree.setText(payScaleData[2]);
				break;
			case 3://货到付款
				//隐藏分期ui
				llReleaseGoodsPaytypeForInstallment.setVisibility(View.GONE);
				//设置分期的textview的值
				etScaleOne.setText(payScaleData[0]);
				etScaleTwo.setText(payScaleData[1]);
				etScaleThree.setText(payScaleData[2]);
				break;
		}

		//挂单方式

		tvReleaseGoodsPublishType.setText(ownGoodsDetailBean.getRes().getPublish_type_str());

		int publishTypeId = Integer.parseInt(ownGoodsDetailBean.getRes().getPublish_type());


		switch (publishTypeId) {
			case 1://1仓单挂单
				rlReleaseGoodsStorePic.setVisibility(View.VISIBLE);
				rlReleaseGoodsSellMargin.setVisibility(View.GONE);
				rlReleaseGoodsSellCredit.setVisibility(View.GONE);

				storePic=ownGoodsDetailBean.getRes().getStore_pic();
				if (null==storePic||"".equals(storePic)){
					storePic="";
					isUsestorePic=false;
				}else{
					isUsestorePic=true;
				}

				if (isUsestorePic) {
					tvReleaseGoodsStorePic.setText("已添加");
				} else {
					tvReleaseGoodsStorePic.setText("未添加");
				}

				break;
			case 2://2保证金挂单
				rlReleaseGoodsStorePic.setVisibility(View.GONE);
				rlReleaseGoodsSellMargin.setVisibility(View.VISIBLE);
				rlReleaseGoodsSellCredit.setVisibility(View.GONE);
				//计算保证金
				//calculateMargin();
				calculateMarginAndCredit();
				break;
			case 3://3信誉挂单
				rlReleaseGoodsStorePic.setVisibility(View.GONE);
				rlReleaseGoodsSellMargin.setVisibility(View.GONE);
				rlReleaseGoodsSellCredit.setVisibility(View.VISIBLE);
				//计算信誉值
				//calculateCredit();
				calculateMarginAndCredit();
				break;
		}

		//所在地
		tvReleaseGoodsDeliveryArea.setText(ownGoodsDetailBean.getRes().getDelivery_area());
		tvReleaseGoodsDeliveryType.setText(ownGoodsDetailBean.getRes().getDelivery_type_str());
		tvReleaseGoodsStartTime.setText(ownGoodsDetailBean.getRes().getStart_time_format());
		tvReleaseGoodsEndTime.setText(ownGoodsDetailBean.getRes().getEnd_time_format());
		etReleaseGoodsRemark.setText(ownGoodsDetailBean.getRes().getRemark());


	}

	@Override
	public void onClick(View v) {
		switch (v.getId()) {
			case R.id.title_left_img:
				finish();
				break;
			case R.id.title_right_tv://下一步
				// 测试
              /*  Intent intent1 = new Intent();
                intent1.setClass(ReleaseGoodsActivity.this, AddGoodsStepTwoActivity.class);
                intent1.putExtra("addTo",0);
                intent1.putExtra("catId","10");
                intent1.putExtra("objectId","192");

                startActivity(intent1);*/
           /* //临时注销  */
				if (releaseGoodsState == 1) {//发布商品进入的
					nextStep();
				} else if (releaseGoodsState == 2) {//返回进入的

				} else if (releaseGoodsState == 3) {//商品详情进入的
					nextStepForDeTail();
				}
				break;
			case R.id.rl_release_goods_classify://商品分类
				chooseClassify();
				break;
			case R.id.rl_release_goods_push_type://发布类型
				showPop(oneModelListForGoodsPushType, rlReleaseGoodsPushType, 1);
				break;
			case R.id.bt_check_user://查询定向用户是否存在
				checkUser();
				break;
			case R.id.rl_release_goods_issplit://是否拆分
				showPop(oneModelListForGoodsIssplit, rlReleaseGoodsIssplit, 1);
				break;
			case R.id.rl_release_goods_paytype://支付方式
				showPop(oneModelListForGoodsPaytype, rlReleaseGoodsPaytype, 1);
				break;
			case R.id.rl_release_goods_publish_type://挂单方式
				showPop(oneModelListForGoodsPublishType, rlReleaseGoodsPublishType, 1);
				break;
			case R.id.rl_release_goods_store_pic://仓单图片
				Intent intentForStorePic = getIntent();
				intentForStorePic.setClass(this, ReleaseGoodsStorePicActivity.class);
				intentForStorePic.putExtra("storePic",storePic);
				intentForStorePic.putExtra("releaseGoodsState", releaseGoodsState);//如果是商品详情进入的3 则进去后不能编辑
				startActivityForResult(intentForStorePic, STORE_PIC_REQUEST_CODE);
				break;
			case R.id.rl_release_goods_delivery_type://交割方式
				showPop(oneModelListForGoodsDeliveryType, rlReleaseGoodsDeliveryType, 1);
				break;
			case R.id.rl_release_goods_delivery_area://交割地（所在地）
				chooseDeliveryArea();
				break;
			case R.id.rl_release_goods_start_time://开始时间
				showTimePop("选择开始时间", rlReleaseGoodsStartTime);
				break;
			case R.id.rl_release_goods_end_time://结束时间
				showTimePop("选择结束时间", rlReleaseGoodsEndTime);
				break;
			case R.id.rl_release_goods_step_price://阶梯价格
				Intent intent = getIntent();
				intent.setClass(this, AddStepPricesActivity.class);
				intent.putExtra("goodsUnit", goodsUnit);
				intent.putExtra("releaseGoodsState", releaseGoodsState);
				if (releaseGoodsState == 3) {

					Bundle bundle = new Bundle();
					bundle.putSerializable("step_price", (Serializable) ownGoodsDetailBean.getRes().getStep_price());
					intent.putExtras(bundle);
				}
				startActivityForResult(intent, STEP_PRICE_REQUEST_CODE);

				break;
			default:
				break;
		}
	}

	private void checkUser() {//查询定向用户是否存在

		if (TextUtils.isEmpty(etReleaseGoodsToUser.getText())){
			Utils.showToast("请填写用户手机号");
			return;
		}

		GetInfoByNamePhoneSubmitBean getInfoByNamePhoneSubmitBean = new GetInfoByNamePhoneSubmitBean();
		getInfoByNamePhoneSubmitBean.setPhone(etReleaseGoodsToUser.getText()+"");
		GetInfoByNamePhoneModel getInfoByNamePhoneModel = new GetInfoByNamePhoneModel(this, new OnNetBackListener<GetInfoByNamePhoneBean>() {
			@Override
			public void netBack(GetInfoByNamePhoneBean data) {
				if (data == null) {
					Toast.makeText(ReleaseGoodsActivity.this, data.getMsg(), Toast.LENGTH_SHORT).show();
				} else {
					if (data.getStatus() == 1) {
						 goodsToUser = data.getRes().getUser_id();
						 //保存toUser的值
						addGoodsStepOneSubmitBean.setToUser(goodsToUser);
						Toast.makeText(ReleaseGoodsActivity.this, "验证成功", Toast.LENGTH_SHORT).show();
					} else {
						Toast.makeText(ReleaseGoodsActivity.this, data.getMsg(), Toast.LENGTH_SHORT).show();
					}
				}
			}
		});
		getInfoByNamePhoneModel.request(JSONUtil.toJSON(getInfoByNamePhoneSubmitBean),true);
	}

	private void nextStepForDeTail() {
		//跳转到附加信息 传分类id 和 addto
		goodsNumber = etReleaseGoodsNumber.getText().toString();//数量
		Utils.showLog( "======详情查看的时候 goodsNumber:"+goodsNumber);
		Intent intent = new Intent();
		intent.setClass(ReleaseGoodsActivity.this, AddGoodsStepTwoActivity.class);
		if (!TextUtils.isEmpty(goodsNumber) && Utils.isNum(goodsNumber)) {
			intent.putExtra("goodsNumber", Double.parseDouble(goodsNumber));
		}
		intent.putExtra("addTo", addTo);
		intent.putExtra("catId", catId);
		intent.putExtra("objectId", objectId);
		intent.putExtra("goodsStatus", goodsStatus);
		intent.putExtra("releaseGoodsState", releaseGoodsState);
		startActivityForResult(intent, STEP_TWO_REQUEST_CODE);
	}


	final List<OneModel> oneModelListForGoodsClassify = new ArrayList<OneModel>();//商品分类滚轮一级
	final List<OneModel> oneModelListForGoodsPushType = new ArrayList<OneModel>();//发布类型滚轮一级 addto
	final List<OneModel> oneModelListForGoodsIssplit = new ArrayList<OneModel>();//是否拆分滚轮一级
	final List<OneModel> oneModelListForGoodsPaytype = new ArrayList<OneModel>();//支付方式滚轮一级
	final List<OneModel> oneModelListForGoodsPublishType = new ArrayList<OneModel>();//挂单方式滚轮一级
	final List<OneModel> oneModelListForGoodsDeliveryType = new ArrayList<OneModel>();//交割方式滚轮一级
	final List<OneModel> oneModelListForDeliveryArea = new ArrayList<OneModel>();//交割地滚轮一级

	/**
	 * 交割地（所在地）
	 */
	private void chooseDeliveryArea() {
		//区域
		if (ConstantClass.areaBean == null) {
			AreaSubmitBean areaSubmitBean = new AreaSubmitBean("recursion");
			new AreaBeanModel(this, new OnNetBackListener<AreaBean>() {
				@Override
				public void netBack(AreaBean data) {
					if (data == null) {

					} else {
						if (data.getStatus() == 1) {
							initAreaData(data);
							ConstantClass.areaBean = data;
						} else {
							Toast.makeText(ReleaseGoodsActivity.this, data.getMsg(), Toast.LENGTH_SHORT).show();
						}
					}
				}
			}).request(JSONUtil.toJSON(areaSubmitBean), true);
		} else {
			//已经有不请求网络
			initAreaData(ConstantClass.areaBean);
		}
	}

	/**
	 * 拆分地区分类数据
	 *
	 * @param data
	 */
	private void initAreaData(AreaBean data) {
		oneModelListForDeliveryArea.clear();
		//一级
		List<AreaBean.ResBean> res = data.getRes();//原始数据
		Utils.showLog("==============res.size=" + res.size());
		for (int i = 0; i < res.size(); i++) {
			OneModel oneModel = new OneModel();
			oneModel.setId(res.get(i).getId());
			oneModel.setName(res.get(i).getName());

			//  二级
			List<TwoModel> twoModelList2 = new ArrayList<TwoModel>();//滚轮二级
			for (int j = 0; j < res.get(i).getChild().size(); j++) {

				TwoModel twoModel = new TwoModel();
				twoModel.setId(res.get(i).getChild().get(j).getId());
				twoModel.setName(res.get(i).getChild().get(j).getName());

				List<ThreeModel> threeModelList3 = new ArrayList<ThreeModel>();//滚轮三级
				for (int h = 0; h < res.get(i).getChild().get(j).getChild().size(); h++) {
					ThreeModel threeModel = new ThreeModel();
					threeModel.setId(res.get(i).getChild().get(j).getChild().get(h).getId());
					threeModel.setName(res.get(i).getChild().get(j).getChild().get(h).getName());
					threeModelList3.add(threeModel);

					twoModel.setThreeModelList(threeModelList3);

				}
				twoModelList2.add(twoModel);
			}
			oneModel.setTwoModelList(twoModelList2);
			oneModelListForDeliveryArea.add(oneModel);
		}
		showPop(oneModelListForDeliveryArea, rlReleaseGoodsDeliveryArea, 3);
	}

	GoodsCategoryBeanTest goodsCategoryBeanTest;//获取的分类的集合

	/**
	 * 获取分类
	 */
	private void chooseClassify() {
		//测试gson以及三级滚轮赋值
		GoodsCategorySubmitBean goodsCategorySubmitBean = new GoodsCategorySubmitBean();
		goodsCategorySubmitBean.setLevel("level");
		goodsCategorySubmitBean.setKey("no");

		new GoodsCategoryModelTest(this, new OnNetBackListener<GoodsCategoryBeanTest>() {
			@Override
			public void netBack(GoodsCategoryBeanTest data) {
				if (data == null) {

				} else {
					if (data.getStatus().equals("1")) {
						goodsCategoryBeanTest = data;
						oneModelListForGoodsClassify.clear();
						//一级
						List<GoodsCategoryBeanTest.ResBean> res = data.getRes();//原始数据

						Utils.showLog("==============res.size=" + res.size());
						for (int i = 0; i < res.size(); i++) {
							OneModel oneModel = new OneModel();
							oneModel.setId(res.get(i).getId());
							oneModel.setName(res.get(i).getName());

							//  二级
							List<TwoModel> twoModelList2 = new ArrayList<TwoModel>();//滚轮二级
							for (int j = 0; j < res.get(i).getChildren().size(); j++) {

								TwoModel twoModel = new TwoModel();
								twoModel.setId(res.get(i).getChildren().get(j).getId());
								twoModel.setName(res.get(i).getChildren().get(j).getName());

								List<ThreeModel> threeModelList3 = new ArrayList<ThreeModel>();//滚轮三级
								for (int h = 0; h < res.get(i).getChildren().get(j).getChildren().size(); h++) {
									ThreeModel threeModel = new ThreeModel();
									threeModel.setId(res.get(i).getChildren().get(j).getChildren().get(h).getId());
									threeModel.setName(res.get(i).getChildren().get(j).getChildren().get(h).getName());
									threeModelList3.add(threeModel);

									twoModel.setThreeModelList(threeModelList3);

								}
								twoModelList2.add(twoModel);
							}
							oneModel.setTwoModelList(twoModelList2);
							oneModelListForGoodsClassify.add(oneModel);
						}
						showPop(oneModelListForGoodsClassify, rlReleaseGoodsClassify, 3);
					} else {
						Toast.makeText(ReleaseGoodsActivity.this, data.getMsg(), Toast.LENGTH_SHORT).show();
					}
				}
			}
		}).request(JSONUtil.toJSON(goodsCategorySubmitBean), true);
	}

	SkmModiPopup skmModiPopup;

	private void showPop(List<OneModel> oneModelList, View view, int level) {
		skmModiPopup = new SkmModiPopup(this, skmPopOnClickListener, oneModelList, "选择", level, view);
		skmModiPopup.showAtLocation(findViewById(R.id.rl_release_goods),
				Gravity.BOTTOM | Gravity.CENTER_HORIZONTAL, 0, 0);
	}

	public SkmDatePickerPopup skmDatePickerPopup;

	private void showTimePop(String content, View view) {

		//skmDatePickerPopup = new SkmDatePickerPopup(this, skmDatePickerPopupOnClickListener, content, view);
		//添加两个参数 是否需要更改默认当前时间 isShouledChangeDate 更改后的时间 targetDate
		boolean isShouledChangeDate = false;
		long targetDate;
		if ("".equals(addGoodsStepOneSubmitBean.getStartTime())||addGoodsStepOneSubmitBean.getStartTime()==null){//开始时间没有选择 在当前时间添加15天
			isShouledChangeDate = true;
			Date date=new Date();//取时间
			Calendar calendar   = Calendar.getInstance();
			calendar.setTime(date);
			calendar.add(calendar.DATE,15);//把日期往后增加一天.整数往后推,负数往前移动
			targetDate=calendar.getTimeInMillis();
		}else {//开始时间有选择 在开始时间添加15天
			isShouledChangeDate = true;
		  long startTime =  Long.parseLong(addGoodsStepOneSubmitBean.getStartTime()+"000");
			Date date=new Date(startTime);//取时间
			Calendar calendar   = Calendar.getInstance();
			calendar.setTime(date);
			calendar.add(calendar.DATE,15);//把日期往后增加一天.整数往后推,负数往前移动
			targetDate=calendar.getTimeInMillis();
		}
		//如果点击的是开始菜单 则时间默认
		 if (view.getId()==R.id.rl_release_goods_start_time){
			 isShouledChangeDate = false;
		 }

		skmDatePickerPopup = new SkmDatePickerPopup(this, skmDatePickerPopupOnClickListener, content, view,isShouledChangeDate,targetDate);


		skmDatePickerPopup.showAtLocation(findViewById(R.id.rl_release_goods),
				Gravity.BOTTOM | Gravity.CENTER_HORIZONTAL, 0, 0);
	}

	public SkmDatePickerPopup.SkmDatePickerPopupOnClickListener skmDatePickerPopupOnClickListener = new SkmDatePickerPopup.SkmDatePickerPopupOnClickListener() {

		@Override
		public void myOnClick(int year, int month, int day, int hour, int minute, View v, View root) {
			skmDatePickerPopup.dismiss();
          /*  Toast.makeText(ReleaseGoodsActivity.this, "您选择的日期：" + year + "年  "
                    + month + "月  " + day + "日" + hour + "时 " + minute + "分钟", Toast.LENGTH_SHORT).show();*/
			String time = year + "-" + month + "-" + day + " " + hour + ":" + minute;
			Utils.showLog("============时间" + TimeUtil.timeToTimeStampForSecond(time, TimeUtil.fotmatString2));
			switch (root.getId()) {
				case R.id.rl_release_goods_start_time://开始时间
					tvReleaseGoodsStartTime.setText(time);
					//保存开始时间的值
					addGoodsStepOneSubmitBean.setStartTime(TimeUtil.timeToTimeStampForSecond(time, TimeUtil.fotmatString2));
					break;
				case R.id.rl_release_goods_end_time://结束时间
					tvReleaseGoodsEndTime.setText(time);
					//保存结束时间的值
					addGoodsStepOneSubmitBean.setEndTime(TimeUtil.timeToTimeStampForSecond(time, TimeUtil.fotmatString2));
					break;

			}
		}

	};
	public SkmModiPopup.SkmPopOnClickListener skmPopOnClickListener = new SkmModiPopup.SkmPopOnClickListener() {

		@Override
		public void myOnClick(int pOneCurrent, int pTwoCurrent, int pThreeCurrent, View v, View root) {
			skmModiPopup.dismiss();
			switch (root.getId()) {
				case R.id.rl_release_goods_classify://点击商品分类的处理
					//Toast.makeText(ReleaseGoodsActivity.this, "一级：id:" + oneModelList.get(pOneCurrent).getId() + " name:" + oneModelList.get(pOneCurrent).getName()+
					// " 二级：id" + oneModelList.get(pOneCurrent).getTwoModelList().get(pTwoCurrent).getId() + "name:" + oneModelList.get(pOneCurrent).getTwoModelList().get(pTwoCurrent).getName() + "
					// 三级：id" + oneModelList.get(pOneCurrent).getTwoModelList().get(pTwoCurrent).getThreeModelList().get(pThreeCurrent).getId() + "name:" + oneModelList.get(pOneCurrent).getTwoModelList().get(pTwoCurrent).getThreeModelList().get(pThreeCurrent).getName() , Toast.LENGTH_SHORT).show();
					//回显选中的第三项的值
					tvReleaseGoodsClassify.setText(oneModelListForGoodsClassify.get(pOneCurrent).getTwoModelList().get(pTwoCurrent).getThreeModelList().get(pThreeCurrent).getName() + "");

					String catIdOne = oneModelListForGoodsClassify.get(pOneCurrent).getId();
					String catIdTwo = oneModelListForGoodsClassify.get(pOneCurrent).getTwoModelList().get(pTwoCurrent).getId();
                   /* if("8888".equals(catIdTwo)){//二级为空 那么三级也为空 id取第一个  未加判断一般没事
                    }*/
					//选中的分类id 这里分类指的是第三个
					String catIdThree = oneModelListForGoodsClassify.get(pOneCurrent).getTwoModelList().get(pTwoCurrent).getThreeModelList().get(pThreeCurrent).getId();
					//保存选中的分类id的值 这里分类指的是第三个
					addGoodsStepOneSubmitBean.setCatId(catIdThree);
					//根据分类设置单位 这里分类指的是第三个
					goodsUnit = goodsCategoryBeanTest.getRes().get(pOneCurrent).getChildren().get(pTwoCurrent).getChildren().get(pThreeCurrent).getUnit();
					tvReleaseGoodsUnit.setText("(" + goodsUnit + ")：");
					tvReleaseGoodsLeastNumberUnit.setText("(" + goodsUnit + ")：");

					break;
				case R.id.rl_release_goods_push_type://发布类型
					tvReleaseGoodsPushType.setText(oneModelListForGoodsPushType.get(pOneCurrent).getName() + "");
					//如果是云商城 隐藏定向用户 显示商城ui 隐藏阶梯价格 ；如果是云拍卖 隐藏可否拆分出售 且值为不可以拆分显示拍卖ui；定向单 隐藏拆分出售 且值为不可以拆分显示商城ui
					switch (Integer.parseInt(oneModelListForGoodsPushType.get(pOneCurrent).getId())) {
						case 0://商城
							llReleaseGoodsForMall.setVisibility(View.VISIBLE);
							llReleaseGoodsForAuction.setVisibility(View.GONE);
							rlReleaseGoodsToUser.setVisibility(View.GONE);

							rlReleaseGoodsIssplit.setVisibility(View.VISIBLE);//显示是否拆分出售
							if ("0".equals(addGoodsStepOneSubmitBean.getIsPorted())) {//不可拆分
								rlReleaseGoodsLeastNumber.setVisibility(View.GONE);
								rlReleaseGoodsStepPrice.setVisibility(View.GONE);//不可拆分就隐藏阶梯价格
								etReleaseGoodsLeastNumber.setText("");
								tvReleaseGoodsIssplit.setText("否");
								isUseStepPrice = false;
								stepPrice = "";
								addGoodsStepOneSubmitBean.setStepPrice(stepPrice);
							} else {
								rlReleaseGoodsLeastNumber.setVisibility(View.VISIBLE);
								rlReleaseGoodsStepPrice.setVisibility(View.VISIBLE);//可拆分就显示阶梯价格
								tvReleaseGoodsIssplit.setText("是");
							}


							if (isUseStepPrice) {
								tvReleaseGoodsStepPrice.setText("启用");
							} else {
								tvReleaseGoodsStepPrice.setText("未启用");
							}
							//支付方式可选择
							rlReleaseGoodsPaytype.setClickable(true);
							//重置拍卖里的值
							etReleaseGoodsTotalPrice.setText("");
							etReleaseGoodsBuyMargin.setText("");
							etReleaseGoodsLeastAdd.setText("");
							etReleaseGoodsFixedPrice.setText("");
							break;
						case 1://拍卖
							llReleaseGoodsForMall.setVisibility(View.GONE);
							llReleaseGoodsForAuction.setVisibility(View.VISIBLE);
							rlReleaseGoodsToUser.setVisibility(View.GONE);
							//不可拆分出售
							addGoodsStepOneSubmitBean.setIsPorted("0");

							//付款方式只能是全款
							//隐藏分期ui
							llReleaseGoodsPaytypeForInstallment.setVisibility(View.GONE);
							//设置分期的textview的值
							etScaleOne.setText("100");
							etScaleTwo.setText("0");
							etScaleThree.setText("0");
							//保存支付方式的值
							addGoodsStepOneSubmitBean.setPayType("1");
							//支付方式不可选择
							rlReleaseGoodsPaytype.setClickable(false);
							tvReleasePaytype.setText("全款");

							//重置商城或者定向单里的值
							etReleaseGoodsPrice.setText("");
							etReleaseGoodsLeastNumber.setText("");
							tvReleaseGoodsIssplit.setText("否");
							isUseStepPrice = false;
							stepPrice = "";
							addGoodsStepOneSubmitBean.setStepPrice(stepPrice);
							break;
						case 2://定向单
							llReleaseGoodsForMall.setVisibility(View.VISIBLE);
							llReleaseGoodsForAuction.setVisibility(View.GONE);
							rlReleaseGoodsToUser.setVisibility(View.VISIBLE);
							//不可拆分出售
							addGoodsStepOneSubmitBean.setIsPorted("0");
							rlReleaseGoodsIssplit.setVisibility(View.GONE);//隐藏是否拆分出售
							rlReleaseGoodsLeastNumber.setVisibility(View.GONE);//隐藏最小订货量
							rlReleaseGoodsStepPrice.setVisibility(View.GONE);//不可拆分就隐藏阶梯价格

							//重置拍卖里的值
							etReleaseGoodsTotalPrice.setText("");
							etReleaseGoodsBuyMargin.setText("");
							etReleaseGoodsLeastAdd.setText("");
							etReleaseGoodsFixedPrice.setText("");
							break;
					}
					//保存发布类型的值
					addGoodsStepOneSubmitBean.setAddTo(oneModelListForGoodsPushType.get(pOneCurrent).getId());
					addTo = Integer.parseInt(addGoodsStepOneSubmitBean.getAddTo());
					//计算保证金和信誉值
					calculateMarginAndCredit();
					break;
				case R.id.rl_release_goods_issplit://是否拆分 0否 1是 如果是否 则隐藏最小供应量 且设置值为0
					tvReleaseGoodsIssplit.setText(oneModelListForGoodsIssplit.get(pOneCurrent).getName() + "");

					if ("0".equals(oneModelListForGoodsIssplit.get(pOneCurrent).getId())) {//不可拆分
						rlReleaseGoodsLeastNumber.setVisibility(View.GONE);
						etReleaseGoodsLeastNumber.setText("");
						rlReleaseGoodsStepPrice.setVisibility(View.GONE);//不可拆分就隐藏阶梯价格
						isUseStepPrice = false;
						stepPrice = "";
						addGoodsStepOneSubmitBean.setStepPrice(stepPrice);
					} else {
						rlReleaseGoodsLeastNumber.setVisibility(View.VISIBLE);
						rlReleaseGoodsStepPrice.setVisibility(View.VISIBLE);//可拆分显示阶梯价格
					}
					//保存是否拆分的值
					addGoodsStepOneSubmitBean.setIsPorted(oneModelListForGoodsIssplit.get(pOneCurrent).getId());
					break;
				case R.id.rl_release_goods_paytype://支付方式 1全款（100，0，0） 2分期 3货到付款（0，0，100）  分期显示分期ui,其余的隐藏   "payScale": "20,50,30",
					tvReleasePaytype.setText(oneModelListForGoodsPaytype.get(pOneCurrent).getName() + "");

					switch (Integer.parseInt(oneModelListForGoodsPaytype.get(pOneCurrent).getId())) {
						case 1://全款
							//隐藏分期ui
							llReleaseGoodsPaytypeForInstallment.setVisibility(View.GONE);
							//设置分期的textview的值
							etScaleOne.setText("100");
							etScaleTwo.setText("0");
							etScaleThree.setText("0");
							break;
						case 2://分期
							//显示分期ui
							llReleaseGoodsPaytypeForInstallment.setVisibility(View.VISIBLE);
							//设置分期的textview的值
							etScaleOne.setText("0");
							etScaleTwo.setText("0");
							etScaleThree.setText("0");
							break;
						case 3://货到付款
							//隐藏分期ui
							llReleaseGoodsPaytypeForInstallment.setVisibility(View.GONE);
							//设置分期的textview的值
							etScaleOne.setText("0");
							etScaleTwo.setText("0");
							etScaleThree.setText("100");
							break;
					}

					//保存支付方式的值
					addGoodsStepOneSubmitBean.setPayType(oneModelListForGoodsPaytype.get(pOneCurrent).getId());
					break;
				case R.id.rl_release_goods_publish_type://挂单方式 1仓单挂单 2保证金挂单 3信誉挂单
					tvReleaseGoodsPublishType.setText(oneModelListForGoodsPublishType.get(pOneCurrent).getName() + "");
					switch (Integer.parseInt(oneModelListForGoodsPublishType.get(pOneCurrent).getId())) {
						case 1://1仓单挂单
							rlReleaseGoodsStorePic.setVisibility(View.VISIBLE);
							rlReleaseGoodsSellMargin.setVisibility(View.GONE);
							rlReleaseGoodsSellCredit.setVisibility(View.GONE);
							if (isUsestorePic) {
								tvReleaseGoodsStorePic.setText("已添加");
							} else {
								tvReleaseGoodsStorePic.setText("未添加");
							}
							break;
						case 2://2保证金挂单
							rlReleaseGoodsStorePic.setVisibility(View.GONE);
							rlReleaseGoodsSellMargin.setVisibility(View.VISIBLE);
							rlReleaseGoodsSellCredit.setVisibility(View.GONE);
							//计算保证金
							// calculateMargin();

							break;
						case 3://3信誉挂单
							rlReleaseGoodsStorePic.setVisibility(View.GONE);
							rlReleaseGoodsSellMargin.setVisibility(View.GONE);
							rlReleaseGoodsSellCredit.setVisibility(View.VISIBLE);
							//计算信誉值
							calculateCredit();
							break;
					}
					//保存挂单方式的值
					addGoodsStepOneSubmitBean.setPublishType(oneModelListForGoodsPublishType.get(pOneCurrent).getId());
					break;
				case R.id.rl_release_goods_delivery_type://交割方式
					tvReleaseGoodsDeliveryType.setText(oneModelListForGoodsDeliveryType.get(pOneCurrent).getName() + "");
					//保存交割方式的值
					addGoodsStepOneSubmitBean.setDeliveryType(oneModelListForGoodsDeliveryType.get(pOneCurrent).getId());
					break;
				case R.id.rl_release_goods_delivery_area://交割地
                       /* "deliveryArea": "山东省青岛市市南区",
                        "province": "28",
                        "city": "128",
                        "county": "512",*/
					//Toast.makeText(ReleaseGoodsActivity.this, "一级：id:" + oneModelList.get(pOneCurrent).getId() + " name:" + oneModelList.get(pOneCurrent).getName()+ " 二级：id" + oneModelList.get(pOneCurrent).getTwoModelList().get(pTwoCurrent).getId() + "name:" + oneModelList.get(pOneCurrent).getTwoModelList().get(pTwoCurrent).getName() + " 三级：id" + oneModelList.get(pOneCurrent).getTwoModelList().get(pTwoCurrent).getThreeModelList().get(pThreeCurrent).getId() + "name:" + oneModelList.get(pOneCurrent).getTwoModelList().get(pTwoCurrent).getThreeModelList().get(pThreeCurrent).getName() , Toast.LENGTH_SHORT).show();
					String deliveryArea = oneModelListForDeliveryArea.get(pOneCurrent).getName() + oneModelListForDeliveryArea.get(pOneCurrent).getTwoModelList().get(pTwoCurrent).getName() + oneModelListForDeliveryArea.get(pOneCurrent).getTwoModelList().get(pTwoCurrent).getThreeModelList().get(pThreeCurrent).getName();
					String province = oneModelListForDeliveryArea.get(pOneCurrent).getId();
					String city = oneModelListForDeliveryArea.get(pOneCurrent).getTwoModelList().get(pTwoCurrent).getId();
					String county = oneModelListForDeliveryArea.get(pOneCurrent).getTwoModelList().get(pTwoCurrent).getThreeModelList().get(pThreeCurrent).getId();

					tvReleaseGoodsDeliveryArea.setText(deliveryArea);
					//保存交割地信息的值
					addGoodsStepOneSubmitBean.setDeliveryArea(deliveryArea);
					addGoodsStepOneSubmitBean.setProvince(province);
					addGoodsStepOneSubmitBean.setCity(city);
					addGoodsStepOneSubmitBean.setCounty(county);

					break;
				default:
					break;
			}

		}
	};

	/**
	 * 计算信誉值
	 */
	private void calculateCredit() {


	}

	/**
	 * 计算保证金信誉值 需要总价 针对不同的发布类型判断
	 */
	private void calculateMarginAndCredit() {
		//计算的type type: goods | invite | auction  保证金挂单 商城 招标 拍卖
		String type = "";
		double money = 0;
		//int addTo = Integer.parseInt(addGoodsStepOneSubmitBean.getAddTo());
		Utils.showLog("=====addTo:" + addTo);
		switch (addTo) {
			case 0://商城
				type = "goods";
				goodsNumber = etReleaseGoodsNumber.getText().toString();//数量
				goodsPrice = etReleaseGoodsPrice.getText().toString();//单价
				if (!TextUtils.isEmpty(goodsNumber) && Utils.isNum(goodsNumber) && !TextUtils.isEmpty(goodsPrice) && Utils.isNum(goodsPrice)) {

					money = Double.parseDouble(goodsNumber) * Double.parseDouble(goodsPrice);
					Utils.showLog("=====商城 money:" + money);
				}
				break;
			case 1://拍卖
				type = "auction";
				goodsNumber= etReleaseGoodsNumber.getText().toString();//数量
				goodsTotalPrice = etReleaseGoodsTotalPrice.getText().toString();//起拍价 总价
				if (!TextUtils.isEmpty(goodsTotalPrice) && Utils.isNum(goodsTotalPrice)) {
					money = Double.parseDouble(goodsTotalPrice);
					Utils.showLog("=====拍卖 money:" + money);
				}
				break;
			case 2://定向单
				type = "goods";
				goodsNumber = etReleaseGoodsNumber.getText().toString();//数量
				goodsPrice = etReleaseGoodsPrice.getText().toString();//单价
				if (!TextUtils.isEmpty(goodsNumber) && Utils.isNum(goodsNumber) && !TextUtils.isEmpty(goodsPrice) && Utils.isNum(goodsPrice)) {
					money = Double.parseDouble(goodsNumber) * Double.parseDouble(goodsPrice);
					Utils.showLog("=====定向单 money:" + money);
				}
				break;
		}

		Utils.showLog("====goodsNumber:" + goodsNumber + " goodsPrice:" + goodsPrice + " money:" + money + "   goodsTotalPrice:" + goodsTotalPrice);

		if (money > 0) {
			// 保证金 "role":"seller","type":"goods","money":"10000","objId":""}
			CalculateMarginSubmitBean calculateMarginSubmitBean = new CalculateMarginSubmitBean();
			calculateMarginSubmitBean.setRole("seller");
			calculateMarginSubmitBean.setType(type);
			calculateMarginSubmitBean.setMoney(money + "");
			calculateMarginSubmitBean.setObjId("");

			new CalculateMarginModel(this, new OnNetBackListener<CalculateMarginBean>() {
				@Override
				public void netBack(CalculateMarginBean data) {
					if (data == null) {
						Toast.makeText(ReleaseGoodsActivity.this, data.getMsg(), Toast.LENGTH_SHORT).show();
					} else {
						if (data.getStatus() == 1) {
							tvCash.setText(data.getRes().getCash());
							tvMargin.setText(data.getRes().getMargin());
						} else {
							Toast.makeText(ReleaseGoodsActivity.this, data.getMsg(), Toast.LENGTH_SHORT).show();
						}
					}
				}
			}).request(JSONUtil.toJSON(calculateMarginSubmitBean), false);

			//	[42]信誉挂单信誉值计算 {"role":"seller","type":"addGoods","money":"10000"}
			CalculateCreditSubmitBean calculateCreditSubmitBean = new CalculateCreditSubmitBean();
			calculateCreditSubmitBean.setRole("seller");
			calculateCreditSubmitBean.setType(type);
			calculateCreditSubmitBean.setMoney(money + "");

			new CalculateCreditModel(this, new OnNetBackListener<CalculateCreditBean>() {
				@Override
				public void netBack(CalculateCreditBean data) {
					if (data == null) {
						Toast.makeText(ReleaseGoodsActivity.this, data.getMsg(), Toast.LENGTH_SHORT).show();
					} else {
						if (data.getStatus() == 1) {
							tvCredit.setText(data.getRes().getCredit());
							tvOwncredit.setText(data.getRes().getOwnCredit());
						} else {
							Toast.makeText(ReleaseGoodsActivity.this, data.getMsg(), Toast.LENGTH_SHORT).show();
						}
					}
				}
			}).request(JSONUtil.toJSON(calculateCreditSubmitBean), false);


		}

	}

	//下一步
	int addTo = 0;
	private boolean checkData() {
		if (tvReleaseGoodsClassify.getText().toString().length() == 0) {
			Toast.makeText(this, "请选择分类", Toast.LENGTH_SHORT).show();
			return false;
		}
		if (etReleaseGoodsTitle.getText().toString().length() == 0) {
			Toast.makeText(this, "请填写商品名称", Toast.LENGTH_SHORT).show();
			return false;
		}
		/*if (etReleaseGoodsPrice.getText().toString().length() == 0) {
			Toast.makeText(this, "请填写单价", Toast.LENGTH_SHORT).show();
			return false;
		}
		if (etReleaseGoodsNumber.getText().toString().length() == 0) {
			Toast.makeText(this, "请填写数量", Toast.LENGTH_SHORT).show();
			return false;
		}*/
		//最小供应量 etReleaseGoodsLeastNumber;
		/*if (etReleaseGoodsMarginScale.getText().toString().length() == 0) {
			Toast.makeText(this, "请填写投标保证金比例", Toast.LENGTH_SHORT).show();
			return false;
		}*/

		//分期 etScaleOne; etScaleTwo; etScaleThree;
		//交割地
		if (tvReleaseGoodsDeliveryArea.getText().toString().length() == 0) {
			Toast.makeText(this, "请选择所在地", Toast.LENGTH_SHORT).show();
			return false;
		}
		if (tvReleaseGoodsDeliveryType.getText().toString().length() == 0) {
			Toast.makeText(this, "请选择交割方式", Toast.LENGTH_SHORT).show();
			return false;
		}
		if (tvReleaseGoodsStartTime.getText().toString().length() == 0) {
			Toast.makeText(this, "请选择开始时间", Toast.LENGTH_SHORT).show();
			return false;
		}
		if (tvReleaseGoodsEndTime.getText().toString().length() == 0) {
			Toast.makeText(this, "请选择结束时间", Toast.LENGTH_SHORT).show();
			return false;
		}
		if ((Long.parseLong(addGoodsStepOneSubmitBean.getStartTime())-Long.parseLong(addGoodsStepOneSubmitBean.getEndTime()))>=0){
			Toast.makeText(this, "结束时间应该晚于开始时间", Toast.LENGTH_SHORT).show();
			return false;
		}

		return true;
	}
	private void nextStep() {
		if (!checkData()) {
			return;
		}
     /*   {
            "catId":"2", "title":"标准精煤100T", "productCode":"山西高能牌", "number":"100.000", "addFrom":
            "0", "addTo":"0", "price":"358.00", "totalPrice":"35800.00", "sellMargin":
            "7160.00", "buyMargin":"0.00", "creditNum":"0", "isPorted":"1", "leastNumber":
            "10.000", "leastAdd":"0", "fixedPrice":"0", "stepPrice":"36,37,38", "payType":
            "2", "payScale":"20,50,30", "publishType":"2", "storePic":"", "toUser":
            "8", "deliveryArea":"山东省青岛市市南区", "province":"28", "city":"128", "county":
            "512", "deliveryType":"1", "startTime":"1470277254", "endTime":"1470286254", "remark":
            "这里是商品备注"
        }*/
		//catId
		addGoodsStepOneSubmitBean.setTitle(etReleaseGoodsTitle.getText().toString());
		addGoodsStepOneSubmitBean.setProductCode(etReleaseGoodsProductCode.getText().toString());
		addGoodsStepOneSubmitBean.setNumber(etReleaseGoodsNumber.getText().toString());
		//addfrom
		//addto
		addGoodsStepOneSubmitBean.setPrice(TextUtils.isEmpty(etReleaseGoodsPrice.getText().toString()) ? "0" : etReleaseGoodsPrice.getText().toString());

		//以下用于计算totalPrice

		addTo = Integer.parseInt(addGoodsStepOneSubmitBean.getAddTo());
		double goodsTotalPriceDouble = 0;
		switch (addTo) {
			case 0://商城
				goodsNumber = etReleaseGoodsNumber.getText().toString();//数量
				goodsPrice = etReleaseGoodsPrice.getText().toString();//单价
				addGoodsStepOneSubmitBean.setAddFrom("0");//这个商品是从哪个功能来的 0代表商品发布
				if (!TextUtils.isEmpty(goodsNumber) && Utils.isNum(goodsNumber) && !TextUtils.isEmpty(goodsPrice) && Utils.isNum(goodsPrice)) {

					goodsTotalPriceDouble = Double.parseDouble(goodsNumber) * Double.parseDouble(goodsPrice);
					Utils.showLog("=====商城 goodsTotalPriceDouble:" + goodsTotalPriceDouble);

				}
				//保存toUser的值
				addGoodsStepOneSubmitBean.setToUser("0");
				break;
			case 1://拍卖
				goodsTotalPrice = etReleaseGoodsTotalPrice.getText().toString();//起拍价 总价
				addGoodsStepOneSubmitBean.setAddFrom("1");//这个商品是从哪个功能来的 1代表拍卖发布
				if (!TextUtils.isEmpty(goodsTotalPrice) && Utils.isNum(goodsTotalPrice)) {
					goodsTotalPriceDouble = Double.parseDouble(goodsTotalPrice);
					Utils.showLog("=====拍卖 goodsTotalPriceDouble:" + goodsTotalPriceDouble);
				}
				//保存toUser的值
				addGoodsStepOneSubmitBean.setToUser("0");
				break;
			case 2://定向单
				goodsNumber = etReleaseGoodsNumber.getText().toString();//数量
				goodsPrice = etReleaseGoodsPrice.getText().toString();//单价
				addGoodsStepOneSubmitBean.setAddFrom("0");//这个商品是从哪个功能来的 0代表商品发布
				if (!TextUtils.isEmpty(goodsNumber) && Utils.isNum(goodsNumber) && !TextUtils.isEmpty(goodsPrice) && Utils.isNum(goodsPrice)) {
					goodsTotalPriceDouble = Double.parseDouble(goodsNumber) * Double.parseDouble(goodsPrice);
					Utils.showLog("=====定向单 money:" + goodsTotalPriceDouble);
				}
				break;
		}
		addGoodsStepOneSubmitBean.setTotalPrice(goodsTotalPriceDouble + "");


		addGoodsStepOneSubmitBean.setBuyMargin(TextUtils.isEmpty(etReleaseGoodsBuyMargin.getText().toString()) ? "0" : etReleaseGoodsBuyMargin.getText().toString());     //buyMargin 买家要交的保证金

		//挂单方式 1仓单挂单 2保证金挂单 3信誉挂单

		switch (Integer.parseInt(addGoodsStepOneSubmitBean.getPublishType())) {
			case 1://1仓单挂单
				addGoodsStepOneSubmitBean.setCredit("0.000");//信誉 信誉挂单所需信誉,谁发布商品就扣谁的
				addGoodsStepOneSubmitBean.setSellMargin("0.00");//卖家保证金
				break;
			case 2://2保证金挂单
				addGoodsStepOneSubmitBean.setCredit("0.000");//信誉 信誉挂单所需信誉,谁发布商品就扣谁的
				addGoodsStepOneSubmitBean.setSellMargin(TextUtils.isEmpty(tvMargin.getText().toString()) ? "0.00" : (Utils.roundForNumber(tvMargin.getText().toString(),2)));//卖家保证金
				break;
			case 3://3信誉挂单
				addGoodsStepOneSubmitBean.setCredit(Utils.roundForNumber(tvCredit.getText().toString(),3));//信誉 信誉挂单所需信誉,谁发布商品就扣谁的
				addGoodsStepOneSubmitBean.setSellMargin("0.00");//卖家保证金
				break;
		}


		//isPorted

		if ("0".equals(addGoodsStepOneSubmitBean.getIsPorted())) {//不拆分 最小供应量等于总量
			addGoodsStepOneSubmitBean.setLeastNumber(etReleaseGoodsNumber.getText().toString());

		} else {
			addGoodsStepOneSubmitBean.setLeastNumber(etReleaseGoodsLeastNumber.getText().toString());
		}


		addGoodsStepOneSubmitBean.setLeastAdd(etReleaseGoodsLeastAdd.getText().toString());
		addGoodsStepOneSubmitBean.setFixedPrice(TextUtils.isEmpty(etReleaseGoodsFixedPrice.getText().toString()) ? "0" : etReleaseGoodsFixedPrice.getText().toString());
		//stepPrice


		//payType 支付方式 1全款 2分期 3货到付款
		String payScale = "";
		if ("1".equals(addGoodsStepOneSubmitBean.getPayType())) {
			payScale = "100,0,0";
		} else if ("2".equals(addGoodsStepOneSubmitBean.getPayType())) {
			payScale = etScaleOne.getText().toString() + "," + etScaleTwo.getText().toString() + "," + etScaleThree.getText().toString();
		} else if ("3".equals(addGoodsStepOneSubmitBean.getPayType())) {
			payScale = "0,0,100";
		}
		addGoodsStepOneSubmitBean.setPayScale(payScale);
		//publishType
		// addGoodsStepOneSubmitBean.setStorePic();
		//addGoodsStepOneSubmitBean.setToUser("0");//不是定向单都为0 这里要修改
		//deliveryArea
		//province
		//city
		//county
		//deliveryType
		//startTime
		//endTime
		addGoodsStepOneSubmitBean.setRemark(etReleaseGoodsRemark.getText().toString());

		//如果是保证金或者信誉挂单，弹出付款信誉界面   2保证金 3信誉
		if (2 == Integer.parseInt(addGoodsStepOneSubmitBean.getPublishType())||3 == Integer.parseInt(addGoodsStepOneSubmitBean.getPublishType())) {
			Intent intentPay = new Intent();
			intentPay.setClass(this, PayForReleaseGoodsActivity.class);

			intentPay.putExtra("publishType", Integer.parseInt(addGoodsStepOneSubmitBean.getPublishType()));
			//保证金的
			intentPay.putExtra("geld", tvMargin.getText().toString());
			intentPay.putExtra("balance", tvCash.getText().toString());
			//信誉的
			intentPay.putExtra("credit", tvCredit.getText().toString());
			intentPay.putExtra("ownCredit", tvOwncredit.getText().toString());

			startActivityForResult(intentPay, PAY_REQUEST_CODE);
		} else {
			addGoodsStepOneSubmit();
		}


	}

	private void addGoodsStepOneSubmit() {
		addGoodsStepOneSubmitBean.setPayPassword(payPassword);

		new AddGoodsStepOneModel(this, new OnNetBackListener<AddGoodsStepOneBean>() {
			@Override
			public void netBack(AddGoodsStepOneBean data) {
				if (data == null) {
					Toast.makeText(ReleaseGoodsActivity.this, data.getMsg(), Toast.LENGTH_SHORT).show();
				} else {
					if (data.getStatus() == 1) {

						//跳转到附加信息 传分类id 和 addto
						Intent intent = new Intent();
						intent.setClass(ReleaseGoodsActivity.this, AddGoodsStepTwoActivity.class);
						if (!TextUtils.isEmpty(goodsNumber) && Utils.isNum(goodsNumber)){
							intent.putExtra("goodsNumber", Double.parseDouble(goodsNumber));
						}
						intent.putExtra("addTo", addTo);
						intent.putExtra("catId", addGoodsStepOneSubmitBean.getCatId());
						intent.putExtra("objectId", data.getRes().getGoods_id());
						releaseGoodsState = 3;//提交后状态需要变化了
						intent.putExtra("releaseGoodsState", releaseGoodsState);
						intent.putExtra("goodsStatus", goodsStatus);
						Utils.showLog("===初次编辑的时候提交的releaseGoodsState：" + releaseGoodsState);
						startActivityForResult(intent, STEP_TWO_REQUEST_CODE);


						Toast.makeText(ReleaseGoodsActivity.this, data.getMsg(), Toast.LENGTH_SHORT).show();
					} else {
						Toast.makeText(ReleaseGoodsActivity.this, data.getMsg(), Toast.LENGTH_SHORT).show();
					}
				}
			}
		}).request(JSONUtil.toJSON(addGoodsStepOneSubmitBean), true);
	}

	@Override
	protected void onActivityResult(int requestCode, int resultCode, Intent data) {
		super.onActivityResult(requestCode, resultCode, data);
		Utils.showLog("=======requestCode=" + requestCode);
		switch (requestCode) {
			case STEP_PRICE_REQUEST_CODE: //是添加阶梯价格返回的
				if (resultCode == STEP_PRICE_RESULT_CODE) {
					stepPrice = data.getStringExtra("stepPrice");
					isUseStepPrice = data.getBooleanExtra("isUseStepPrice", false);

					if (isUseStepPrice) {
						tvReleaseGoodsStepPrice.setText("启用");
					} else {
						tvReleaseGoodsStepPrice.setText("未启用");
					}
					//保存阶梯价格的值
					addGoodsStepOneSubmitBean.setStepPrice(stepPrice);

					Utils.showLog("=======阶梯价格stepPrice：" + addGoodsStepOneSubmitBean.getStepPrice());
				}
				break;
			case STORE_PIC_REQUEST_CODE://是添加仓单返回的
				if (resultCode ==STORE_PIC_RESULT_CODE){//正常返回的
					storePic=data.getStringExtra("storePic");

					if (data.getBooleanExtra("isHaveStorePic",true)) {
						tvReleaseGoodsStorePic.setText("已经编辑");
					} else {
						tvReleaseGoodsStorePic.setText("未编辑");
					}

					//保存仓单id的值
					addGoodsStepOneSubmitBean.setStorePic(storePic);

					Utils.showLog("=======仓单storePic：" + addGoodsStepOneSubmitBean.getStorePic());
				}

				break;
			case PAY_REQUEST_CODE://是付款返回的
				if (resultCode == PAY_RESULT_CODE) {//正常付款返回的
					payPassword=data.getStringExtra("payPassword");
					addGoodsStepOneSubmit();
				}
				break;
			case STEP_TWO_REQUEST_CODE: //是第二步返回的
				if (resultCode == STEP_TWO_RESULT_CODE) {
					addTo = data.getIntExtra("addTo", 0);
					catId = data.getStringExtra("catId");
					objectId = data.getStringExtra("objectId");
					releaseGoodsState = data.getIntExtra("releaseGoodsState", 1);
					Utils.showLog("====返回的releaseGoodsState：" + releaseGoodsState);
					//这里状态是3   状态为3的时候需要goodsId参数
					goodsId=Integer.parseInt(objectId);
					initView();
					initListener();
					init();
				}
				break;
		}
	}

}
